package com.example.demo;


import org.apache.commons.lang3.time.DateUtils;

import java.lang.reflect.Field;

import java.lang.reflect.InvocationTargetException;

import java.lang.reflect.Method;

import java.text.SimpleDateFormat;
import java.util.ArrayList;

import java.util.Calendar;
import java.util.Date;
import java.util.List;


public class TestDate {

    public static void main(String[] args) {

        List list  = new ArrayList();


        //String time = getTime(0);
        //System.out.println(time);
        List<String> sevenDate = getSevenDate();
        System.out.println(sevenDate);
    }

    private  static String getTime(int str){
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Calendar calendarStart = Calendar.getInstance();
        calendarStart.add(Calendar.DATE,str);
        String start = format.format(calendarStart.getTime());
        return start;
    }


    //获取近七天日期
    public static List<String> getSevenDate() {
        List<String> dateList = new ArrayList<>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        for (int i = 0; i < 7; i++) {
            Date date = DateUtils.addDays(new Date(), -i);
            String formatDate = sdf.format(date);
            dateList.add(formatDate);
        }
        return dateList;
    }


}